﻿@using Model;
@{
    Layout = "~/Admin/_AdminSiteLayout.cshtml";
    Page.Title = "Edit Question Type";

    var statusMessage = "";
    bool isValid = false;

        // If this is a POST request, validate and process data
    <link href="@Href("~/Styles/Validation.css")" rel="stylesheet" />

    Validation.RequireField("QuestionType", "You must specify this Question Type or Remove.");

    int requestId = UrlData[0].AsInt();// Request.Form["Id"].AsInt();

    int i = 0;

    QuestionType aQuestionType = null;

    if (!IsPost)
    {
        aQuestionType = SiteHelper.GetQuestionTypeById(requestId);
    }

    if (IsPost)
    {
        DateTime currentDate = DateTime.Now;

        aQuestionType = new QuestionType();

        if (Request.Form["QuestionType"] != null)
        {
            aQuestionType.QType = Request.Form["QuestionType"];

            aQuestionType.CreateDate = currentDate;

        }

        try
        {
            SiteHelper.UpdateQTypeByObjectAndId(aQuestionType, requestId);

            statusMessage = " Type Updated Successfully!";

            isValid = true;

        }
        catch (Exception ex)
        {
            isValid = false;

            statusMessage = "Error!\n" + ex.Message;
        }
    }

}
@* If at least one validation error exists, notify the user *@
@if (!statusMessage.IsEmpty())
{
    if (isValid)
    {
    <p class="message success">
        @statusMessage
    </p>
    }
    else
    {
    <p class="message error">
        @statusMessage
    </p>
    }
}
<form method="post" action="">
<fieldset>
    <legend>Question Type Edit</legend>
    <label>
        Question Type :
    </label>
    <input type="text" id="QuestionType" name="QuestionType"  title="Question Type" placeholder="QuestionType" class="@SiteValidation.GetValidationClass("QuestionType")" @Validation.For("QuestionType") value="@aQuestionType.QType" />
    @Html.ValidationMessage("QuestionType")
    <p class="form-actions">
        <input class="button medium green" type="submit" value="Update" title="Update" />
    </p>
</fieldset>
<script src="@Href("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
<script src="@Href("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Href("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Href("~/cripts/jquery-1.3.2.min.js")" type="text/javascript"></script>
</form>